# -*- coding: utf-8 -*-
"""
@Time ： 2022/12/27 0:29
@Auth ： jiraWu
@File ：post_代码示例.py
@IDE ：PyCharm
@Motto:人生苦短，我学Python

"""

"""
post请求演示
演示爬取广州地区的所有门店信息
"""
from jira_wu_dev_utils._request import PostRequest


def down_load_post(cont: str, page: int):
    with open(f'肯德基门店信息\广州门店第{page}页.json', 'w', encoding='utf-8') as f:
        f.write(cont)
    print(f"第【{page}】页已经完成下载！")


if __name__ == '__main__':
    url = "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname"
    start_page = int(input("起始页码："))
    start_end = int(input("结束页码："))
    for page in range(start_page, start_end + 1):
        data = {
            'cname': '广州',
            'pid': '',
            'pageSize': 10,
            'pageIndex': page
        }
        headers = {
            'Cookie': 'route-cell=ksa; ASP.NET_SessionId=l5y24ysh4jrt2zncomf1y1vs; Hm_lvt_1039f1218e57655b6677f30913227148=1672054633; Hm_lpvt_1039f1218e57655b6677f30913227148=1672054633; SERVERID=825676b1eb536df327d3ca8f626c0188|1672055042|1672054633',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
            'X-Requested-With': 'XMLHttpRequest'
        }
        # 发送代理请求
        # cont = GetRequest(url=url, data=data, headers=headers).proxy_req({'http': '127.0.0.1'})
        # 发送非代理请求
        cont = PostRequest(url=url, data=data, headers=headers).send_req()
        down_load_post(cont, page)
